package cn.itcast.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RuntimeMonitorAspect {

    @Around("execution(* cn.itcast.service.impl.AccountServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint pjp)throws Throwable{
        String className = pjp.getSignature().getDeclaringTypeName();//获取正在执行的类名
        String methodName = pjp.getSignature().getName();//获取正在执行的方法名


        long startTime = System.currentTimeMillis();
        Object result = pjp.proceed(pjp.getArgs());//调用目标对象的方法
        long endTime = System.currentTimeMillis();

        System.out.println(className+"."+methodName+"执行花费了"+(endTime-startTime)+"毫秒");
        return result;
    }
}
